import { state } from '@angular/animations';
import {
    Action,
    createFeatureSelector,
    createReducer,
    createSelector,
    on,
} from '@ngrx/store';
import { AppState } from '../app.model';
import {
    changeMenuCollapse,
    setState,
    updatePageInterval,
    updateSum,
} from './utils.actions';
import { UtilsState } from './utils.model';
export const initialState: UtilsState = {
    city: undefined,
    district: undefined,
    town: undefined,
    village: undefined,
    area: undefined,
    menuCollapse: undefined,
    t: undefined,
    update: 0,
    applicant: undefined,
    department: undefined,
    meterType: undefined,
};
export const utilsReducer = createReducer(
    initialState,
    on(setState, (state, action) => ({
        ...action.utils,
    })),
    on(updateSum, (state, action) => ({
        ...state,
        update: state.update + 1,
    })),
    on(changeMenuCollapse, (state, action) => ({
        ...state,
        menuCollapse: action.menuCollapse,
    })),
    on(updatePageInterval, (state, action) => ({
        ...state,
        t: action.t,
    }))
);
export const getUtilsState = createFeatureSelector<AppState, UtilsState>(
    'utils'
);
export const getCity = createSelector(
    getUtilsState,
    (state: UtilsState) => state.city
);
export const getDistrict = createSelector(
    getUtilsState,
    (state: UtilsState) => state.district
);
export const getTown = createSelector(
    getUtilsState,
    (state: UtilsState) => state.town
);
export const getVillage = createSelector(
    getUtilsState,
    (state: UtilsState) => state.village
);
export const getArea = createSelector(
    getUtilsState,
    (state: UtilsState) => state.area
);
export const getMenuCollapse = createSelector(
    getUtilsState,
    (state: UtilsState) => state.menuCollapse
);
export const getT = createSelector(
    getUtilsState,
    (state: UtilsState) => state.t
);
export const getApplicant = createSelector(
    getUtilsState,
    (state: UtilsState) => state.applicant
);
export const getDepartment = createSelector(
    getUtilsState,
    (state: UtilsState) => state.department
);
export const getMeterType = createSelector(
    getUtilsState,
    (state: UtilsState) => state.meterType
);
